From 428a890bd7396a6a6e3da10303ca2bfa44166417 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=98yvind=20Kol=C3=A5s?= Date: Tue, 1 Apr 2008 22:39:28 +0000 Subject: [PATCH] applied patch from Jan Heller that improves readability by using the newly * babl/babl-classes.h: * babl/babl-conversion.c: * babl/babl-db.c: * babl/babl-fish-path.c: * babl/babl-fish.c: * babl/babl-format.c: * babl/babl-internal.h: * babl/babl-introspect.c: * babl/babl-list.c: * babl/babl-list.h: * babl/babl-model.c: * babl/babl-sampling.c: * babl/babl-sanity.c: * babl/babl-type.c: * babl/babl-util.[ch]: applied patch from Jan Heller that improves readability by using the newly introduced BablList structure. svn path=/trunk/; revision=300 --- ChangeLog | 19 ++++++++++++++ babl/babl-classes.h | 9 ++++--- babl/babl-conversion.c | 4 ++- babl/babl-db.c | 2 +- babl/babl-fish-path.c | 24 +++++++++--------- babl/babl-fish.c | 2 +- babl/babl-format.c | 7 +++--- babl/babl-internal.h | 1 + babl/babl-introspect.c | 35 ++++++++------------------ babl/babl-list.c | 24 ++++++++++-------- babl/babl-list.h | 14 +++++++---- babl/babl-model.c | 5 ++-- babl/babl-sampling.c | 3 ++- babl/babl-sanity.c | 28 +++++++++------------ babl/babl-type.c | 15 +++++------ babl/babl-util.c | 57 ------------------------------------------ babl/babl-util.h | 10 -------- 17 files changed, 103 insertions(+), 156 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4f5f259..e3f3ade 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2008-04-01 Øyvind Kolås + + * babl/babl-classes.h: + * babl/babl-conversion.c: + * babl/babl-db.c: + * babl/babl-fish-path.c: + * babl/babl-fish.c: + * babl/babl-format.c: + * babl/babl-internal.h: + * babl/babl-introspect.c: + * babl/babl-list.c: + * babl/babl-list.h: + * babl/babl-model.c: + * babl/babl-sampling.c: + * babl/babl-sanity.c: + * babl/babl-type.c: + * babl/babl-util.[ch]: applied patch from Jan Heller that improves + readability by using the newly introduced BablList structure. + 2008-03-31 Sven Neumann * AUTHORS: added Jan Heller and obfuscated the email addresses. diff --git a/babl/babl-classes.h b/babl/babl-classes.h index 52cb22f..8544d4e 100644 --- a/babl/babl-classes.h +++ b/babl/babl-classes.h @@ -76,6 +76,7 @@ typedef enum { typedef union _Babl Babl; +typedef struct _BablList BablList; /* common header for any item inserted into database */ typedef struct @@ -109,7 +110,7 @@ BablConversion { typedef struct { BablInstance instance; - BablConversion **from; /*< NULL terminated list of conversions from class */ + BablList *from_list; int bits; /*< number of bits used to represent the data type (initially restricted to a multiple of 8) */ double min_val; @@ -136,7 +137,7 @@ typedef struct typedef struct { BablInstance instance; - BablConversion **from; /*< NULL terminated list of conversions from class */ + BablList *from_list; int horizontal; int vertical; char name[4]; @@ -154,7 +155,7 @@ typedef struct typedef struct { BablInstance instance; - BablConversion **from; /*< NULL terminated list of conversions from class */ + BablList *from_list; int components; BablComponent **component; BablType **type; /*< must be doubles, used here for convenience in code */ @@ -163,7 +164,7 @@ typedef struct typedef struct { BablInstance instance; - BablConversion **from; /*< NULL terminated list of conversions from class */ + BablList *from_list; int components; BablComponent **component; BablType **type; diff --git a/babl/babl-conversion.c b/babl/babl-conversion.c index ab122bb..3dd3f11 100644 --- a/babl/babl-conversion.c +++ b/babl/babl-conversion.c @@ -275,7 +275,9 @@ babl_conversion_new (void *first_arg, * id/name, inserting newly created class into database. */ babl_db_insert (db, babl); - babl_add_ptr_to_list ((void ***) ((Babl *) &(source->type.from)), babl); + if (!source->type.from_list) + source->type.from_list = babl_list_init_with_size (BABL_CONVERSIONS); + babl_list_insert (source->type.from_list, babl); return babl; } diff --git a/babl/babl-db.c b/babl/babl-db.c index 2cd95a7..c5a4480 100644 --- a/babl/babl-db.c +++ b/babl/babl-db.c @@ -111,7 +111,7 @@ babl_db_each (BablDb *db, BablEachFunction each_fun, void *user_data) { - babl_list_each_temp (db->babl_list, each_fun, user_data); + babl_list_each (db->babl_list, each_fun, user_data); } diff --git a/babl/babl-fish-path.c b/babl/babl-fish-path.c index ada4116..6534167 100644 --- a/babl/babl-fish-path.c +++ b/babl/babl-fish-path.c @@ -141,10 +141,10 @@ get_conversion_chain (const Babl *from, temp_chain[temp_conversions] = NULL; babl_assert (from); babl_assert (from->class_type == BABL_FORMAT); - if (!from->format.from) + if (!from->format.from_list) return 0; - babl_list_each ((void **) from->format.from, + babl_list_each (from->format.from_list, chain_gen_each, &context); } @@ -152,12 +152,11 @@ get_conversion_chain (const Babl *from, { if (BABL (temp_chain[temp_conversions - 1]) && BABL (temp_chain[temp_conversions - 1]->destination)-> - format.from) + format.from_list) babl_list_each ( - (void **) BABL (temp_chain[temp_conversions - 1]->destination)-> - format.from, + format.from_list, chain_gen_each, &context); } @@ -250,15 +249,16 @@ static inline Babl * assert_conversion_find (void *source, void *destination) { - int i = 0; - Babl **conversion; + int i = 0; + BablList *conversion_list; + Babl *conversion; - conversion = (void *) BABL (source)->type.from; - while (conversion && conversion[i]) + conversion_list = BABL (source)->type.from_list; + for (i = 0; i < babl_list_size (conversion_list); i++) { - if (conversion[i]->conversion.destination == destination) - return (Babl *) conversion[i]; - i++; + conversion = BABL (conversion_list->items[i]); + if (conversion->conversion.destination == destination) + return conversion; } babl_fatal ("failed, aborting"); return NULL; diff --git a/babl/babl-fish.c b/babl/babl-fish.c index fc8d7e3..c77acaf 100644 --- a/babl/babl-fish.c +++ b/babl/babl-fish.c @@ -41,7 +41,7 @@ babl_conversion_find (const void *source, { void *data = (void*)destination; - babl_list_each ((void *) BABL (source)->type.from, match_conversion, &data); + babl_list_each (BABL (source)->type.from_list, match_conversion, &data); if (data == (void*)destination) /* didn't change */ return NULL; return data; diff --git a/babl/babl-format.c b/babl/babl-format.c index 0a16669..09ccd1c 100644 --- a/babl/babl-format.c +++ b/babl/babl-format.c @@ -27,7 +27,8 @@ static int each_babl_format_destroy (Babl *babl, void *data) { - babl_free (babl->format.from); + if (babl->format.from_list) + babl_list_destroy (babl->format.from_list); babl_free (babl); return 0; /* continue iterating */ @@ -74,7 +75,7 @@ format_new (const char *name, sizeof (int) * (components) + sizeof (int) * (components)); - babl->format.from = NULL; + babl->format.from_list = NULL; babl->format.component = (void *) (((char *) babl) + sizeof (BablFormat)); babl->format.type = (void *) (((char *) babl->format.component) + sizeof (BablComponent *) * (components)); babl->format.sampling = (void *) (((char *) babl->format.type) + sizeof (BablType *) * (components)); @@ -110,7 +111,7 @@ format_new (const char *name, static char buf[512] = ""; -static const char * +static char * create_name (BablModel *model, int components, BablComponent **component, diff --git a/babl/babl-internal.h b/babl/babl-internal.h index 12e19df..e9c4028 100644 --- a/babl/babl-internal.h +++ b/babl/babl-internal.h @@ -25,6 +25,7 @@ #define BABL_MAX_COMPONENTS 32 #define BABL_HARD_MAX_PATH_LENGTH 8 +#define BABL_CONVERSIONS 5 #include #include diff --git a/babl/babl-introspect.c b/babl/babl-introspect.c index dd1c430..d632ff8 100644 --- a/babl/babl-introspect.c +++ b/babl/babl-introspect.c @@ -78,37 +78,22 @@ babl_introspect (Babl *babl) } #ifdef BABL_LOG -static int list_length (void **list) -{ - void **ptr; - int len = 0; - - ptr = list; - while (NULL != *ptr) - { - ptr++; - len++; - } - return len; -} - static void item_conversions_introspect (Babl *babl) { - void **ptr; - - if (babl->type.from) - babl_log ("\t\tconversions from %s: %i", - babl->instance.name, list_length ((void **) (babl->type.from))); - - ptr = (void **) babl->type.from; + int i; + BablList *list; - while (ptr && NULL != *ptr) + list = babl->type.from_list; + if (list) { - babl_log ("\t\t\t'%s'", ((Babl *) (*ptr))->instance.name); - ptr++; - } + babl_log ("\t\tconversions from %s: %i", + babl->instance.name, babl_list_size (list)); + + for (i = 0; i < babl_list_size (list); i++) + babl_log ("\t\t\t'%s'", BABL (list->items[i])->instance.name); + } } static void diff --git a/babl/babl-list.c b/babl/babl-list.c index e67a5c8..9dbd959 100644 --- a/babl/babl-list.c +++ b/babl/babl-list.c @@ -16,11 +16,8 @@ * . */ -/* Implementation of list data structure. This is a bit superior - * to the list implementation in babl-util.c. +/* Implementation of list data structure. * Copyright (C) 2008, Jan Heller - * - * TODO: migrate babl to BablList */ #include "babl-internal.h" @@ -29,12 +26,20 @@ BablList * babl_list_init (void) +{ + return babl_list_init_with_size (BABL_LIST_INITIAL_SIZE); +} + +BablList * +babl_list_init_with_size (int initial_size) { BablList *list = babl_calloc (sizeof (BablList), 1); babl_assert (list); - list->size = BABL_LIST_INITIAL_SIZE; + if (initial_size == 0) + initial_size = 1; + list->size = initial_size; list->count = 0; list->items = NULL; if (list->size) @@ -81,13 +86,10 @@ babl_list_insert (BablList *list, list->items[list->count++] = item; } -/* TODO: Rename babl_list_each_temp to babl_list_each after the list migration - */ - void -babl_list_each_temp (BablList *list, - BablEachFunction each_fun, - void *user_data) +babl_list_each (BablList *list, + BablEachFunction each_fun, + void *user_data) { int i; diff --git a/babl/babl-list.h b/babl/babl-list.h index af05fe8..07047cc 100644 --- a/babl/babl-list.h +++ b/babl/babl-list.h @@ -20,12 +20,13 @@ #define _BABL_LIST_H #ifndef _BABL_CLASSES_H +/* babl-classes.h contains forward declaration + * typedef struct _BablList BablList; + */ #error babl-list.h is only to be included after babl-classes.h #endif -typedef struct _BablList BablList; - typedef struct _BablList { int count; @@ -37,6 +38,9 @@ typedef struct _BablList BablList * babl_list_init (void); +BablList * +babl_list_init_with_size (int initial_size); + void babl_list_destroy (BablList *list); @@ -48,9 +52,9 @@ babl_list_insert (BablList *list, Babl *item); void -babl_list_each_temp (BablList *list, - BablEachFunction each_fun, - void *user_data); +babl_list_each (BablList *list, + BablEachFunction each_fun, + void *user_data); #endif diff --git a/babl/babl-model.c b/babl/babl-model.c index 6a212b5..2d3fe08 100644 --- a/babl/babl-model.c +++ b/babl/babl-model.c @@ -27,7 +27,8 @@ static int each_babl_model_destroy (Babl *babl, void *data) { - babl_free (babl->model.from); + if (babl->model.from_list) + babl_list_destroy (babl->model.from_list); babl_free (babl); return 0; /* continue iterating */ } @@ -72,7 +73,7 @@ model_new (const char *name, strcpy (babl->instance.name, name); memcpy (babl->model.component, component, sizeof (BablComponent *) * components); - babl->model.from = NULL; + babl->model.from_list = NULL; return babl; } diff --git a/babl/babl-sampling.c b/babl/babl-sampling.c index 039d57c..3f73142 100644 --- a/babl/babl-sampling.c +++ b/babl/babl-sampling.c @@ -46,7 +46,8 @@ static int each_babl_sampling_destroy (Babl *babl, void *data) { - babl_free (babl->sampling.from); + if (babl->sampling.from_list) + babl_list_destroy (babl->sampling.from_list); return 0; /* continue iterating */ } diff --git a/babl/babl-sanity.c b/babl/babl-sanity.c index 085c4e4..e2beb64 100644 --- a/babl/babl-sanity.c +++ b/babl/babl-sanity.c @@ -36,22 +36,20 @@ type_sanity (Babl *babl, { /* ensure that every type has reference conversions to * and from double */ - void **ptr; - int ok; + int ok, i; + BablList *list; ok = 0; - if (babl->type.from) + list = babl->type.from_list; + if (list) { - ptr = (void **) babl->type.from; - - while (ptr && NULL != *ptr) + for (i = 0; i < babl_list_size (list); i++) { - if (babl_conversion_destination ((Babl *) (*ptr)) == babl_type_id (BABL_DOUBLE)) + if (babl_conversion_destination ((Babl *) list->items[i]) == babl_type_id (BABL_DOUBLE)) { ok = 1; break; } - ptr++; } } if (!ok) @@ -71,22 +69,20 @@ model_sanity (Babl *babl, { /* ensure that every type has reference conversions to * and from rgba */ - void **ptr; - int ok; + int ok, i; + BablList *list; ok = 0; - if (babl->model.from) + list = babl->model.from_list; + if (list) { - ptr = (void **) babl->model.from; - - while (ptr && NULL != *ptr) + for (i = 0; i < babl_list_size (list); i++) { - if (babl_conversion_destination ((Babl *) (*ptr)) == babl_model_id (BABL_RGBA)) + if (babl_conversion_destination ((Babl *) list->items[i]) == babl_model_id (BABL_RGBA)) { ok = 1; break; } - ptr++; } } if (!ok) diff --git a/babl/babl-type.c b/babl/babl-type.c index 3a182e2..b2ba824 100644 --- a/babl/babl-type.c +++ b/babl/babl-type.c @@ -28,7 +28,8 @@ static int each_babl_type_destroy (Babl *babl, void *data) { - babl_free (babl->type.from); + if (babl->type.from_list) + babl_list_destroy (babl->type.from_list); babl_free (babl); return 0; /* continue iterating */ } @@ -44,13 +45,13 @@ type_new (const char *name, babl_assert (bits != 0); babl_assert (bits % 8 == 0); - babl = babl_malloc (sizeof (BablType) + strlen (name) + 1); - babl->instance.name = (void *) ((char *) babl + sizeof (BablType)); - babl->class_type = BABL_TYPE; - babl->instance.id = id; + babl = babl_malloc (sizeof (BablType) + strlen (name) + 1); + babl->instance.name = (void *) ((char *) babl + sizeof (BablType)); + babl->class_type = BABL_TYPE; + babl->instance.id = id; strcpy (babl->instance.name, name); - babl->type.bits = bits; - babl->type.from = NULL; + babl->type.bits = bits; + babl->type.from_list = NULL; return babl; } diff --git a/babl/babl-util.c b/babl/babl-util.c index ffa2ad3..70756e8 100644 --- a/babl/babl-util.c +++ b/babl/babl-util.c @@ -16,66 +16,9 @@ * . */ -#include -#include -#include #include -#include "babl-memory.h" #include "babl-internal.h" -static int list_length (void **list) -{ - void **ptr; - int len = 0; - - ptr = list; - while (NULL != *ptr) - { - ptr++; - len++; - } - return len; -} - -void -babl_add_ptr_to_list (void ***list, - void *new) -{ - int orig_len = 0; - - if (*list) - { - orig_len = list_length (*list); - } - - *list = babl_realloc ((*list), - sizeof (void *) * (orig_len + 2)); - - if (!(*list)) - { - babl_fatal ("failed to realloc"); - } - - (*list)[orig_len] = new; - (*list)[orig_len + 1] = NULL; -} - -void -babl_list_each (void **list, - BablEachFunction each_fun, - void *user_data) -{ - int i; - - if (!list) - return; - for (i = 0; i < list_length (list); i++) - { - if (each_fun ((Babl *) list[i], user_data)) - break; - } -} - #include #include diff --git a/babl/babl-util.h b/babl/babl-util.h index 3932dde..923a6b3 100644 --- a/babl/babl-util.h +++ b/babl/babl-util.h @@ -19,16 +19,6 @@ #ifndef _BABL_UTIL_H #define _BABL_UTIL_H -#include - -void babl_add_ptr_to_list (void ***list, - void *new); - -void -babl_list_each (void **list, - BablEachFunction each_fun, - void *user_data); - long babl_ticks (void); -- 2.30.2